//
//  ChinaTableViewCell.m
//  GoodBuy
//
//  Created by dlios on 15-5-14.
//  Copyright (c) 2015年 GoodBuy. All rights reserved.
//

#import "ChinaTableViewCell.h"

@implementation ChinaTableViewCell
- (void)dealloc
{
    [_article_mall release];
    [_pictureView release];
    [_article_format_date release];
    [_article_pic release];
    [_article_price release];
    [_article_title release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}
- (void)createSubviews {
    
    //-------------去掉点击效果
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    //------------设置底图View
    
    self.pictureView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, [UIScreen mainScreen].bounds.size.width - self.pictureView.frame.origin.x*2, [UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2)];
    
    _pictureView.backgroundColor = [[UIColor alloc] initWithRed:0.2 green:0.4 blue:0.2 alpha:0.1];
    
    _pictureView.contentMode = 2;
    _pictureView.layer.masksToBounds = YES;
    _pictureView.layer.cornerRadius = 20;
    _pictureView.layer.frame = CGRectMake(5, 5, [UIScreen mainScreen].bounds.size.width - self.pictureView.frame.origin.x*2, [UIScreen mainScreen].bounds.size.height/4 - 5);
    [self.contentView addSubview:self.pictureView];
    [_pictureView release];
    
    //-------------设置标题(字体大小\换行设置)
    
    self.article_title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    _article_title.frame = CGRectMake([UIScreen mainScreen].bounds.size.width / 3, ([UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2) / 4, [UIScreen mainScreen].bounds.size.width / 1.6, ([UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2) / 3);
    _article_title.numberOfLines = 0;
    [_article_title setTextAlignment:NSTextAlignmentLeft];
    _article_title.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_article_title];
    [_article_title release];
    
    // -------------------图片
    
    self.article_pic = [[UIImageView alloc] initWithFrame:CGRectMake(10, 25, [UIScreen mainScreen].bounds.size.width / 3.6, [UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2-55- 30)];
    _article_pic.layer.masksToBounds = YES;
    _article_pic.layer.cornerRadius = 20;
    _article_pic.contentMode = 2;
    [self.contentView addSubview:_article_pic];
    [_article_pic release];
    
    // -----------------商城
    
    self.article_mall = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 3, ([UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2) / 9 , [UIScreen mainScreen].bounds.size.width / 3.5,25)];
    _article_mall.textColor = [UIColor grayColor];
    _article_mall.font = [UIFont systemFontOfSize:18];
    [self.contentView addSubview:_article_mall];
    [_article_mall release];
    
    // ---------------时间
    
    self.article_format_date = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 1.5, ([UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2) / 9, [UIScreen mainScreen].bounds.size.width / 3.6, ([UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2-55) / 9 + 2)];
    _article_format_date.textColor = [UIColor grayColor];
    _article_format_date.font = [UIFont systemFontOfSize:15];
    [_article_format_date setTextAlignment:NSTextAlignmentRight];
    [self.contentView addSubview:_article_format_date];
    [_article_format_date release];
    
    // -----------价钱
    
    self.article_price = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 3, ([UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2-55) / 1.3 + 5, [UIScreen mainScreen].bounds.size.width / 1.5, 35)];
    _article_price.numberOfLines = 0;
    [_article_price setTextColor:[UIColor redColor]];
    _article_price.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_article_price];
    [_article_price release];

}

// ------------------赋值

- (void)setChinaList:(YBChinaList *)chinaList
{
    if (chinaList != _chinaList) {
        [_chinaList release];
        _chinaList = [chinaList retain];
    }
    NSURL *pic = [NSURL URLWithString:chinaList.article_pic];
    [_article_pic sd_setImageWithURL:pic placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    _article_mall.text = chinaList.article_mall;
    _article_price.text = chinaList.article_price;
    _article_title.text = chinaList.article_title;
    _article_format_date.text = chinaList.article_format_date;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
